import React from 'react';
import { Badge } from 'antd';
const statusCN = {
    emergency: '1-紧急',
    high: '2-高级',
    mid: '3-中级',
    junior: '4-初级',
    info: '5-提示',
    '1-emergency': '1-紧急',
    '2-high': '2-高级',
    '3-mid': '3-中级',
    '4-junior': '4-初级',
    '5-info': '5-提示',
    indicator: '指标告警',
    event: '事件告警',
    'cpu-usage': 'CPU使用率',
    'disk-iops-read': '存储读IOPS',
    'disk-iops-write': '存储写IOPS',
    'disk-usage': '存储使用率',
    'mem-usage': '内存使用率',
    'nic-byte-in': '网络流入速率',
    'nic-byte-out': '网络流出速率',
};

const status = (value) => {
    return statusCN[value] || value;
};

const statusFun = (value, s, c) => {
    if (typeof value == 'undefined') return '-';
    if (!s[value]) return value;
    return <Badge status={c[value]} text={s[value]} />;
};

// 告警状态
const alarmStatusCN = {
    0: '采集中',
    1: '正在告警',
    '-1': '已恢复',
};

const alarmclassCN = {
    0: 'error',
    1: 'error',
    '-1': 'success',
};

const alarmStatusFun = (value) => {
    return statusFun(`${value}`, alarmStatusCN, alarmclassCN);
};

// 确认状态
const confirmStatusCN = {
    true: '已确认',
    false: '未确认',
    0: '未确认',
    1: '已确认',
};

const confirmclassCN = {
    true: 'success',
    false: 'error',
    0: 'error',
    1: 'success',
};

const confirmStatus = (value) => {
    value = value || 0;
    return statusFun(value, confirmStatusCN, confirmclassCN);
};
const confirmTooltip = (value) => {
    value = value || 0;
    return confirmStatusCN[value] || value;
};
// 规则状态
const ruleStatusCN = {
    1: '启用',
    0: '禁用',
};

const ruleClassCN = {
    1: 'success',
    0: 'error',
};

const ruleStatus = (value) => {
    return statusFun(value, ruleStatusCN, ruleClassCN);
};

/*  ---------------  信息 --------------   */

const infoTypeFileter = [
    { text: '指标告警', value: '指标告警' },
    { text: '事件告警', value: '事件告警' },
];

const infoRankFileter = [
    {
        text: '1-紧急',
        value: '1-emergency',
    },
    {
        text: '2-高级',
        value: '2-high',
    },
    {
        text: '3-中级',
        value: '3-mid',
    },
    {
        text: '4-初级',
        value: '4-junior',
    },
    {
        text: '5-提示',
        value: '5-info',
    },
];

const infoConfirmStatusFileter = [
    { text: '已确认', value: 1 },
    { text: '未确认', value: 0 },
];

const infoAlarmStatusFilter = [
    { text: '采集中', value: 0 },
    { text: '正在告警', value: 1 },
    { text: '已恢复', value: -1 },
];

/*  ---------------  通知、规则 --------------   */

const statusFilters = [
    { text: '禁用', value: '0' },
    { text: '启用', value: '1' },
];

const alarmRankCN = {
    1: '1-紧急',
    2: '2-高级',
    3: '3-中级',
    4: '4-初级',
    5: '5-提示',
};

const rankStatus = (value) => {
    return alarmRankCN[value] || value;
};

const alarmModeCN = {
    1: '短信',
    2: '邮件',
    3: '消息',
};

const modeStatus = (value) => {
    return alarmModeCN[value] || value;
};

const alarmSendCN = {
    1: '成功',
    0: '失败',
};

const sendStatus = (value) => {
    return alarmSendCN[value] || value;
};

// 统计周期
const statPeriodList = [
    // {
    // 	name:"1分钟",
    // 	value:1,
    // },
    {
        name: '5分钟',
        value: 5,
    },
];
//统计方式
const statisticModeList = [
    {
        name: '累计触发',
        value: "1",
    },
]

//波动周期
const fluctuationList = [
    // {
    //     name: '5分钟',
    //     value: 'fiveMinutes',
    // },
    {
        name: '半小时',
        value: 'halfHour',
    },
    {
        name: '小时',
        value: 'hour',
    },
    {
        name: '半天',
        value: 'halfDay',
    },
    {
        name: '天',
        value: 'day',
    },
    {
        name: '周',
        value: 'week',
    },
    {
        name: '月',
        value: 'month',
    },
];
const sensitivityList = [
    {
        name: '0',
        value: 1,
    },
    {
        name: '10',
        value: 10,
    },
    {
        name: '20',
        value: 20,
    },
    {
        name: '30',
        value: 30,
    },
    {
        name: '40',
        value: 40,
    },
    {
        name: '50',
        value: 50,
    },
    {
        name: '60',
        value: 60,
    },
    {
        name: '70',
        value: 70,
    },
    {
        name: '80',
        value: 80,
    },
    {
        name: '90',
        value: 90,
    },
    {
        name: '100',
        value: 100,
    },
]
// 持续周期
const duraPeriodList = [
    {
        name: '1个周期',
        value: 1,
    },
    {
        name: '2个周期',
        value: 2,
    },
    {
        name: '3个周期',
        value: 3,
    },
    {
        name: '4个周期',
        value: 4,
    },
];
const intellectFilter = [
    { text: '是', value: 1 },
    { text: '否', value: 0 },
];
const intellectStatus = (value) => {
    let index = intellectFilter.findIndex(item => item.value === value)
    return index !== -1 ? intellectFilter[index].text : value;
};
// 取值
const takeValueList = [
    {
        name: '最大值',
        value: 'max',
    },
    {
        name: '最小值',
        value: 'min',
    },
    {
        name: '平均值',
        value: 'avg',
    },
];
// 判断方法
const judgMethodList = [
    {
        name: '大于',
        value: 'gt',
    },
    {
        name: '小于',
        value: 'lt',
    },
    {
        name: '大于等于',
        value: 'gte',
    },
    {
        name: '小于等于',
        value: 'lte',
    },
    {
        name: '等于',
        value: 'eq',
    },
    {
        name: '不等于',
        value: 'ne',
    },
];
// 告警级别
const alarmRankList = [
    {
        name: '1-紧急',
        value: 1,
    },
    {
        name: '2-高级',
        value: 2,
    },
    {
        name: '3-中级',
        value: 3,
    },
    {
        name: '4-初级',
        value: 4,
    },
    {
        name: '5-提示',
        value: 5,
    },
];
// 告警级别完整
const alarmTotalRankList = [
    {
        name: '1-紧急',
        value: '1-emergency',
    },
    {
        name: '2-高级',
        value: '2-high',
    },
    {
        name: '3-中级',
        value: '3-mid',
    },
    {
        name: '4-初级',
        value: '4-junior',
    },
    {
        name: '5-提示',
        value: '5-info',
    },
];
// 告警级别铃声设置
const alarmPlayerMap = {
    '1-emergency': 'emergencyTone',
    '2-high': 'highTone',
    '3-mid': 'midTone',
    '4-junior': 'juniorTone',
    '5-info': 'infoTone',
}
// 告警方式
const alarmModeList = [
    // {
    // 	name:"短信",
    // 	value:1,
    // },
    {
        name: '邮件',
        value: 2,
    },
    {
        name: '消息',
        value: 3,
    },
];
// 触发方式
const triggerModeList = [
    {
        name: '告警出现',
        value: 1,
    },
    {
        name: '告警恢复',
        value: 2,
    },
];

const arrayToObject = (list) => {
    let obj = {};
    list?.map((item) => (obj[item.value] = item.name));
    return obj;
};

const alarmStatus = {
    status,
    alarmStatusFun,
    confirmStatus,
    confirmTooltip,
    ruleStatus,
    infoTypeFileter,
    infoRankFileter,
    infoConfirmStatusFileter,
    rankStatus,
    modeStatus,
    statusFilters,
    statPeriodList,
    statisticModeList,
    fluctuationList,
    sensitivityList,
    duraPeriodList,
    judgMethodList,
    intellectFilter,
    intellectStatus,
    takeValueList,
    alarmRankList,
    alarmTotalRankList,
    alarmPlayerMap,
    alarmModeList,
    triggerModeList,
    sendStatus,
    infoAlarmStatusFilter,
    arrayToObject,
    ruleStatusCN,
    alarmStatusCN,
    confirmStatusCN
};
export default alarmStatus;
